<?php
namespace app\admin\controller\station;

use app\admin\model\ChargingStation;
use app\admin\model\CityArea;
use app\admin\model\SystemAdmin;
use app\admin\model\SystemMenu;
use app\admin\BaseController;
use app\admin\model\SystemRole;
use think\facade\Db;
use think\facade\Log;
use think\App;
use think\facade\View;
use think\facade\Request;

class Tixin extends BaseController
{
    /**
     * 列表页面
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {

        return View::fetch('tixin/index');
    }
    public function list(){
        $list = Db::table('jy_user_bank')->order('id', 'desc')->select()->toArray();
        for($i=0;$i<count($list);$i++){
            $list[$i]['create_time'] = date("Y-m-d H:i:s", $list[$i]['create_time']); // 输出格式为年-月-日 时:分:秒
            if($list[$i]['status']==0){
                $list[$i]['status'] = '未审核';
            }else if($list[$i]['status']==1){
                $list[$i]['status'] = '已审核';
            }else{
                $list[$i]['status'] = '已驳回';
            }
        }
        $backData['data'] = $list;
        // 设置成功的响应代码和消息
        $backData['code'] = 0;
        $backData['msg'] = '获取成功';
        return json($backData); // ThinkPHP的json方法会自动设置Content-Type为application/json
    }
    function editForm(){
        $Id = Request::get('id');
        $list = Db::table('jy_user_bank')->where('id',$Id)->find();
        foreach ($list as $key => $value){
            if($key=='create_time'){
                $list[$key] = date("Y-m-d H:i:s", $value); // 输出格式为年-月-日 时:分:秒
            }
            if($key=='uid'){
                $list[$key] = Db::table('jy_user')->where('id',$value)->value('account');
            }
        }
        View::assign('list', $list);
        View::assign('id', $Id);
        return View::fetch('tixin/edit');
    }
    function updateData(){
        $getData = Request::post();
        if($getData['status'] == 2){
            $list = Db::table('jy_user_bank')->where('id',$getData['id'])->find();
            $user = Db::table('jy_user')->where('id',$list['uid'])->find();
            $data = [
                'now_money' => $user['now_money'] + $list['money'],
            ];
            Db::table('jy_user')->where('id',$user['id'])->update($data);
        }
        $result = Db::table('jy_user_bank')->where('id',$getData['id'])
            ->update(['status' => $getData['status']]);

        if($result) return $this->success('修改成功');
        return $this->fail('未作任何修改');
    }
}


